﻿using System;
using System.Collections.Generic;
using System.Text;
using RemoteBank.Interface;
using RemoteBank.Entities;
using RemoteBank.DAL;
using System.Data;
using System.Data.SqlClient;

namespace RemoteBank.BLL
{
    class UserBLL : InterfaceUser
    {


        #region InterfaceUser Members

        public bool Login(string UserName, string Password)
        {
            RemoteBankDAL dal = new RemoteBankDAL();
            SqlDataReader dr;
            SqlParameter para;
            List<SqlParameter> ListPara = new List<SqlParameter>();

            para = new SqlParameter("@userName", SqlDbType.VarChar);
            para.Value = UserName;
            ListPara.Add(para);

            para = new SqlParameter("@Password", SqlDbType.VarChar);
            para.Value = Password;
            ListPara.Add(para);

            dr = dal.ExecuteQuerry_GetDataReader("Login",ListPara);
            if(dr.HasRows)
            {
                return true;
            }
            else
            {
                return false;
            }


        }

        public RemoteBank.Entities.User GetUser(String UserName)
        {
            User user = new User();
            RemoteBankDAL dal = new RemoteBankDAL();
            SqlDataReader reader;
            SqlParameter para;
            List<SqlParameter> ListPara = new List<SqlParameter>();

            para = new SqlParameter("@UserName",SqlDbType.VarChar);
            para.Value = UserName;
            ListPara.Add(para);
            reader = dal.ExecuteQuerry_GetDataReader("getUserByUserName", ListPara);
            if (reader.HasRows)
            {
                reader.Read();
                user.Userid = Convert.ToInt32(reader[0].ToString());
                user.Username = reader[1].ToString();
                user.Password = reader[2].ToString();
                user.Email = reader[3].ToString();
                user.Phone = reader[4].ToString();
                user.Address = reader[5].ToString();
                user.Fullname = reader[6].ToString();
                user.Gender = reader[7].ToString();
                return user;
            }
            else
            {
                return null;
            }


        }

        public System.Data.DataTable GetAccount()
        {
            throw new NotImplementedException();
        }

        public void AccReport()
        {
            throw new NotImplementedException();
        }

        public void LogOut()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
